<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise-封装 | 7 - 异步任务 then 方法实现 </title>
    <script src="./promise.js" ></script>
</head>
<body>
    <script>

        //实例化对象
        let p=new Promise((resolve,reject)=>{
 
            //回调的执行时机:
            //1.如果说是同步调用,是在then方法调用的时候执行回调函数
            //2.如果是异步任务,应该是在改变状态的时候执行回调
            
            //同步
            //resolve('OK');

            //异步
            setTimeout(()=>{
                //resolve('OK');
                reject('ERROR');
            },1000);
        });


        p.then(value=>{
            console.log(value);
        },reason=>{
            console.warn(reason);
        });


        console.log(p);
 

    </script>
</body>
</html>